package com.hbnu.tonghengchang;

public class UserRegistration {

    public User register(String username,String password, String email){
        User user=null;
        int i;
        boolean flag=false;
        for (i=0;i<username.length();i++){
            flag = false;
            if (Character.isLetterOrDigit(username.charAt(i))&&username.length()>=3&&username.length()<=20)
                flag=true;
        }
        if (flag==true){
            for (i=0;i<password.length();i++){
                flag=false;
                if (Character.isLetterOrDigit(password.charAt(i))&&password.length()>=6&&password.length()<=20){
                    flag=true;
                    if (email.matches("^[A-Za-z0-9\\u4e00-\\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$")){
                        user = new User();
                        user.setUsername(username);
                        user.setPassword(password);
                        user.setEmail(email);
                        break;
                    }else {
                        System.out.println("您的邮箱格式输入错误，请重新输入！！");
                        break;
                    }
                }
            }if (flag==false) System.out.println("密码至少需要6位且要包含数字和字母，请重新输入！！");
        }else {
            System.out.println("用户名至少需要3位且只能为字母或数字，请重新输入！！");
        }

        return user;
    }
}

